﻿namespace Authentication.Data.DataContextStorage
{
    using System.Web;
    public class DataContextStorageFactory
    {
        /// <summary>
        /// The _data context storage container.
        /// </summary>
        public static IDataContextStorageContainer _dataContextStorageContainer;

        /// <summary>
        /// The create storage container.
        /// </summary>
        /// <returns>
        /// The <see cref="IDataContextStorageContainer"/>.
        /// </returns>
        public static IDataContextStorageContainer CreateStorageContainer()
        {
            if (_dataContextStorageContainer == null)
            {
                if (HttpContext.Current == null)
                {
                    _dataContextStorageContainer = new ThreadDataContextStorageContainer();
                }
                else
                {
                    _dataContextStorageContainer = new HttpDataContextStorageContainer();
                }
            }

            return _dataContextStorageContainer;
        }
    }
}
